{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import { SupabaseVectorStore } from \"@langchain/community/vectorstores/supabase\";\n",
    "import { OpenAIEmbeddings } from \"@langchain/openai\";\n",
    "import { createClient } from \"@supabase/supabase-js\";\n",
    "import dotenv from \"dotenv\";\n",
    "dotenv.config();\n",
    "\n",
    "const embeddings = new OpenAIEmbeddings({\n",
    "    model: \"text-embedding-3-small\",\n",
    "  });\n",
    "\n",
    "  const supabaseClient = createClient(\n",
    "    process.env.SUPABASE_URL ?? '',\n",
    "    process.env.SUPABASE_SERVICE_ROLE_KEY ?? '',\n",
    "  );\n",
    "  const vectorStore = new SupabaseVectorStore(embeddings, {\n",
    "    client: supabaseClient,\n",
    "    tableName: 'documents',\n",
    "    queryName: 'match_documents',\n",
    "  });\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  pageContent: 'UNITED\\tSTATES\\n' +\n",
      "    'SECURITIES\\tAND\\tEXCHANGE\\tCOMMISSION\\n' +\n",
      "    'Washington,\\tD.C.\\t20549\\n' +\n",
      "    'FORM\\t10-K\\n' +\n",
      "    '(Mark\\tOne)\\n' +\n",
      "    'xANNUAL\\tREPORT\\tPURSUANT\\tTO\\tSECTION\\t13\\tOR\\t15(d)\\tOF\\tTHE\\tSECURITIES\\tEXCHANGE\\tACT\\tOF\\t1934\\n' +\n",
      "    'For\\tthe\\tfiscal\\tyear\\tended\\tDecember\\t31,\\t2023\\n' +\n",
      "    'OR\\n' +\n",
      "    'oTRANSITION\\tREPORT\\tPURSUANT\\tTO\\tSECTION\\t13\\tOR\\t15(d)\\tOF\\tTHE\\tSECURITIES\\tEXCHANGE\\tACT\\tOF\\t1934\\n' +\n",
      "    'For\\tthe\\ttransition\\tperiod\\tfrom\\t_________\\tto\\t_________\\n' +\n",
      "    'Commission\\tFile\\tNumber:\\t001-34756\\n' +\n",
      "    'Tesla,\\tInc.\\n' +\n",
      "    '(Exact\\tname\\tof\\tregistrant\\tas\\tspecified\\tin\\tits\\tcharter)\\n' +\n",
      "    'Delaware91-2197729\\n' +\n",
      "    '(State\\tor\\tother\\tjurisdiction\\tof\\n' +\n",
      "    'incorporation\\tor\\torganization)\\n' +\n",
      "    '(I.R.S.\\tEmployer\\n' +\n",
      "    'Identification\\tNo.)\\n' +\n",
      "    '1\\tTesla\\tRoad\\n' +\n",
      "    'Austin,\\tTexas78725\\n' +\n",
      "    '(Address\\tof\\tprincipal\\texecutive\\toffices)(Zip\\tCode)\\n' +\n",
      "    '(512)\\t516-8177\\n' +\n",
      "    '(Registrant’s\\ttelephone\\tnumber,\\tincluding\\tarea\\tcode)\\n' +\n",
      "    'Securities\\tregistered\\tpursuant\\tto\\tSection\\t12(b)\\tof\\tthe\\tAct:\\n' +\n",
      "    'Title\\tof\\teach\\tclassTrading\\tSymbol(s)Name\\tof\\teach\\texchange\\ton\\twhich\\tregistered\\n' +\n",
      "    'Common\\tstockTSLAThe\\tNasdaq\\tGlobal\\tSelect\\tMarket\\n' +\n",
      "    'Securities\\tregistered\\tpursuant\\tto\\tSection\\t12(g)\\tof\\tthe\\tAct:\\n' +\n",
      "    'None\\n' +\n",
      "    'Indicate\\tby\\tcheck\\tmark\\twhether\\tthe\\tregistrant\\tis\\ta\\twell-known\\tseasoned\\tissuer,\\tas\\tdefined\\tin\\tRule\\t405\\tof\\tthe\\tSecurities\\tAct.\\tYes\\tx\\tNo\\to\\n' +\n",
      "    'Indicate\\tby\\tcheck\\tmark\\tif\\tthe\\tregistrant\\tis\\tnot\\trequired\\tto\\tfile\\treports\\tpursuant\\tto\\tSection\\t13\\tor\\t15(d)\\tof\\tthe\\tAct.\\tYes\\to\\tNo\\tx\\n' +\n",
      "    'Indicate\\tby\\tcheck\\tmark\\twhether\\tthe\\tregistrant\\t(1)\\thas\\tfiled\\tall\\treports\\trequired\\tto\\tbe\\tfiled\\tby\\tSection\\t13\\tor\\t15(d)\\tof\\tthe\\tSecurities\\tExchange\\tAct\\tof\\t1934\\t(“Exchange\\tAct”)\\n' +\n",
      "    'during\\tthe\\tpreceding\\t12\\tmonths\\t(or\\tfor\\tsuch\\tshorter\\tperiod\\tthat\\tthe\\tregistrant\\twas\\trequired\\tto\\tfile\\tsuch\\treports),\\tand\\t(2)\\thas\\tbeen\\tsubject\\tto\\tsuch\\tfiling\\trequirements\\tfor\\tthe\\tpast\\t90\\n' +\n",
      "    'days.\\tYes\\tx\\tNo\\to\\n' +\n",
      "    'Indicate\\tby\\tcheck\\tmark\\twhether\\tthe\\tregistrant\\thas\\tsubmitted\\telectronically\\tevery\\tInteractive\\tData\\tFile\\trequired\\tto\\tbe\\tsubmitted\\tpursuant\\tto\\tRule\\t405\\tof\\tRegulation\\tS-T\\n' +\n",
      "    '(§232.405\\tof\\tthis\\tchapter)\\tduring\\tthe\\tpreceding\\t12\\tmonths\\t(or\\tfor\\tsuch\\tshorter\\tperiod\\tthat\\tthe\\tregistrant\\twas\\trequired\\tto\\tsubmit\\tsuch\\tfiles).\\tYes\\tx\\tNo\\to',\n",
      "  metadata: {\n",
      "    source: './test_docs/test-tsla-10k-2023.pdf',\n",
      "    pdf: {\n",
      "      version: '1.10.100',\n",
      "      info: [Object],\n",
      "      metadata: null,\n",
      "      totalPages: 130\n",
      "    },\n",
      "    loc: { pageNumber: 1, lines: [Object] },\n",
      "    uuid: 'f96c76fd-d49a-476e-8565-29bbe5d60101'\n",
      "  },\n",
      "  id: 'f96c76fd-d49a-476e-8565-29bbe5d60101'\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "import { PDFLoader } from \"@langchain/community/document_loaders/fs/pdf\";\n",
    "import { RecursiveCharacterTextSplitter } from \"@langchain/textsplitters\";\n",
    "import { writeFile } from \"fs/promises\";\n",
    "import { reduceDocs } from \"./src/shared/state.js\";\n",
    "\n",
    "const pdfPath = \"./test_docs/test-tsla-10k-2023.pdf\"\n",
    "\n",
    "const loader = new PDFLoader(pdfPath);\n",
    "\n",
    "const docs = await loader.load();\n",
    "\n",
    "\n",
    "const textSplitter = new RecursiveCharacterTextSplitter({\n",
    "    chunkSize: 2000,\n",
    "    chunkOverlap: 50,\n",
    "  });\n",
    "const docSplits = await textSplitter.splitDocuments(docs);\n",
    "\n",
    "const finalDocs = reduceDocs([], docSplits);\n",
    "\n",
    "  \n",
    "finalDocs[0]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[\n",
      "  'f96c76fd-d49a-476e-8565-29bbe5d60101',\n",
      "  'cf036396-4b2b-46fb-9ca4-20bbd6a3947e',\n",
      "  'f725b551-cdad-4b17-9681-6c7ac07742aa',\n",
      "  '950dc7ea-3040-4e32-926f-3d2ad76598ba',\n",
      "  'd756834a-3b9c-4ac4-90f2-5a5bb9a88b89',\n",
      "  '15dcb874-9a11-414c-a612-4ba9ac78df9b',\n",
      "  '27c14e27-544b-4e2d-bd30-5271fc1c1945',\n",
      "  'c087b995-9b3c-43c9-849e-1ffccfa710e0',\n",
      "  'ac0b84ff-f893-4a95-aaad-c79b9951c32e',\n",
      "  '2f176e4f-1128-47ee-8803-ee004b725458',\n",
      "  'b72bf8bd-47be-4392-8781-1fee00cd8028',\n",
      "  'f87b847c-07e7-4e87-8a73-533028f7d778',\n",
      "  'a2a571cf-bbec-40b6-a5e7-8a33fd36d1dd',\n",
      "  '2405ac0e-8041-41e6-b8d2-c695a03a8a9a',\n",
      "  '157becfc-79c8-43f6-941b-df7e62a51811',\n",
      "  '79d2e706-1212-4a89-85f6-ff117f8a43cc',\n",
      "  '97353508-c3d5-4c16-9b13-ab792aabd89b',\n",
      "  'c63472f4-bd4d-4469-96a5-8eb01cd5fad2',\n",
      "  '0f221405-317e-4c2a-ac61-7ad049a3bcf4',\n",
      "  'de3767fe-d129-4218-b062-4b3c689797a6',\n",
      "  'ba25d45b-6d25-467e-bf25-0106088d9da8',\n",
      "  '4a391f87-1ccb-4f66-8cc8-d7a7f98c1455',\n",
      "  '844ef3dc-9281-4912-9ddb-52260891237d',\n",
      "  'c9b88bc9-6711-4c1d-a44d-878f3c9567d3',\n",
      "  'cff9d8f9-0037-4666-a9a6-bbdce8ec6281',\n",
      "  'a59d30c4-4ff6-4ade-b7b7-72130510fdc2',\n",
      "  '8189a997-b7db-412c-a24a-d2ad899996c3',\n",
      "  '3b84ebcb-83ff-4c28-a820-ba220b1182e0',\n",
      "  'cee3e54f-28da-44ba-8e89-3e7190da9c4d',\n",
      "  '7b8c2bfd-4e60-4dc0-9925-d91f12687bb9',\n",
      "  '6ee122b7-711c-41b3-8cff-c91c937521fb',\n",
      "  '90cfc70d-ed91-40df-a950-6156b58a958d',\n",
      "  'f65b5f7c-6188-4fbc-97a3-fe4a9a0195ef',\n",
      "  '93838d7f-cbc1-49c0-b1c3-7346890a33c6',\n",
      "  '4a151e15-2168-4c82-9328-ec9b38d74a33',\n",
      "  '468454c2-3de2-4fb9-94d4-0401bd6bbe5a',\n",
      "  '9ec60200-82d7-4be9-ac08-0b23ec063bbd',\n",
      "  'c14d0c79-9fcf-4881-97b9-28a26909623b',\n",
      "  '5dd44111-2198-4450-a775-a127f1871113',\n",
      "  '893ebdd6-03c4-4bb0-804c-6450c878a9ea',\n",
      "  '31a4d42a-7754-4577-8ba3-0a3f8211de83',\n",
      "  '77d5342d-4ba5-456b-8847-f4035db744fc',\n",
      "  '99b1d564-b7c2-4ca1-9ffc-32a166750e79',\n",
      "  'b42d8825-beb6-408d-a52a-ee173c0145e1',\n",
      "  'f8c0c005-4d91-46f7-b814-9b4b13899e30',\n",
      "  '6ba1713f-edc4-42bd-860b-96919be6571d',\n",
      "  'aa5bc2b5-4f0a-4c22-9612-998c5cd69bb1',\n",
      "  '91b91359-d140-458e-8fab-83ee5453a790',\n",
      "  '9f0bf3da-5c8e-45aa-bc48-3d4e61c3ebdb',\n",
      "  '1be204e4-70b0-47fc-b21e-7224eab69a75',\n",
      "  'be8393f0-ca5f-45c9-b1d7-986a303d0369',\n",
      "  '89be8879-eb8b-46a6-82e2-e51792f681b9',\n",
      "  '2522017c-9477-472d-8108-d76459ba8aa7',\n",
      "  'a691255f-4a4c-48ec-a3a3-80aba6c18c79',\n",
      "  'd2fb69aa-4717-445f-92cb-508218940968',\n",
      "  'db3123f4-4123-46b9-b9f4-0e6e1fa7e3c3',\n",
      "  '40f718e8-6881-4bb9-9d39-13aab528056d',\n",
      "  'a5dbff0a-3b09-4d12-b8ad-654bce0f5dee',\n",
      "  '6aea630d-a505-49cf-8d10-8174bd4faa15',\n",
      "  '496d2ee5-ab26-46b4-8b9d-7acc9ea36075',\n",
      "  'd34e623c-072f-49d3-9e94-4b70fcda51b2',\n",
      "  '18e26f1c-e144-4777-8f5f-776de83fb3be',\n",
      "  '938c7da4-2359-488e-89b8-fb4be3ce5b01',\n",
      "  'e6ebe707-26b2-4b18-91cc-a4a331217b2a',\n",
      "  'b025fdeb-35b7-46cc-85d1-3ec4ca0caddc',\n",
      "  'ddead230-69b3-410d-9eea-e89545dfff25',\n",
      "  'fb934adb-735c-4fed-a052-d896ddd437bf',\n",
      "  'ae420132-f438-4ff4-b992-3a3ccb69a5ef',\n",
      "  '38784dc9-ecdd-4759-97a8-4ee22aca4634',\n",
      "  '9d56a989-f2d2-4ad5-9e49-1898dd6e75f2',\n",
      "  '18400d6c-ab86-4f50-86aa-4b234b62f009',\n",
      "  'a4494df8-bfd6-44c6-b8b2-b81ff61a74fe',\n",
      "  'f8f51316-2feb-4b31-9e46-4689bf46787c',\n",
      "  'df12bf50-6dd4-492b-9c18-0e2e4841a4a4',\n",
      "  '34ceec9a-0016-43c0-8c55-7fcfe4495a8b',\n",
      "  'bbf9a474-4f3a-4abf-9342-699d2e9fe409',\n",
      "  '4f6ea7fc-2786-45f1-a4d2-7ecfbd36582a',\n",
      "  '71767cfe-8200-4971-820b-73129cdc9545',\n",
      "  '202e0e63-e8a5-4f7d-8484-4d46aad50d7f',\n",
      "  'bd131dd5-5d7b-45b1-9799-1ffb62d98797',\n",
      "  '1feb01f4-846c-494d-a6b8-5f4537fca483',\n",
      "  'a2c43dbe-dd5a-49eb-9cf6-38746b7d1f5c',\n",
      "  'd8c2ffce-9430-4a0b-8693-1aacca4182dd',\n",
      "  '315485dc-3489-4d76-872e-265b70a48bed',\n",
      "  '6068a764-8f01-4cbd-97f5-53350c8a05a0',\n",
      "  'c6f489c6-e661-4dd0-a648-94876c401f76',\n",
      "  'b807e746-b164-4d77-9920-add981023992',\n",
      "  'f326c9c3-fec6-4261-aad3-ca1e6c24e3e0',\n",
      "  '4c03255a-7007-4b62-89f9-7102969d292b',\n",
      "  '771daa63-07ad-4342-b1e8-8ea7236b5e03',\n",
      "  '0dc20776-a46a-49cf-a85e-9d76fd294360',\n",
      "  'd6270cad-f2c1-4832-84dd-af0d4b757226',\n",
      "  '1d105310-5247-4bf1-8594-c8f32b2d1b7e',\n",
      "  'bc5e8845-9e7e-4c4d-be6f-46eda519185d',\n",
      "  'fd844e2f-d433-46c2-87d6-b3c64535a8a2',\n",
      "  '7381ceeb-a2b0-4ff9-b72f-3cbf8f1641b8',\n",
      "  '52751f69-2718-4306-b7ec-57a142906aa2',\n",
      "  '2772db49-0b98-4c5d-9814-82c5b7439271',\n",
      "  'a622b09e-03bd-4a18-a927-5c52dfb9293e',\n",
      "  '06e6b02a-6967-44d3-aa7f-13cec5746ab3',\n",
      "  ... 193 more items\n",
      "]\n"
     ]
    }
   ],
   "source": [
    "const documentIds = finalDocs.map((doc) => doc.id);\n",
    "await vectorStore.addDocuments(finalDocs, {ids: documentIds});\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  error: null,\n",
      "  data: [\n",
      "    { id: 'f96c76fd-d49a-476e-8565-29bbe5d60101' },\n",
      "    { id: 'cf036396-4b2b-46fb-9ca4-20bbd6a3947e' },\n",
      "    { id: 'f725b551-cdad-4b17-9681-6c7ac07742aa' },\n",
      "    { id: '950dc7ea-3040-4e32-926f-3d2ad76598ba' },\n",
      "    { id: 'd756834a-3b9c-4ac4-90f2-5a5bb9a88b89' },\n",
      "    { id: '15dcb874-9a11-414c-a612-4ba9ac78df9b' },\n",
      "    { id: '27c14e27-544b-4e2d-bd30-5271fc1c1945' },\n",
      "    { id: 'c087b995-9b3c-43c9-849e-1ffccfa710e0' },\n",
      "    { id: 'ac0b84ff-f893-4a95-aaad-c79b9951c32e' },\n",
      "    { id: '2f176e4f-1128-47ee-8803-ee004b725458' },\n",
      "    { id: 'b72bf8bd-47be-4392-8781-1fee00cd8028' },\n",
      "    { id: 'f87b847c-07e7-4e87-8a73-533028f7d778' },\n",
      "    { id: 'a2a571cf-bbec-40b6-a5e7-8a33fd36d1dd' },\n",
      "    { id: '2405ac0e-8041-41e6-b8d2-c695a03a8a9a' },\n",
      "    { id: '157becfc-79c8-43f6-941b-df7e62a51811' },\n",
      "    { id: '79d2e706-1212-4a89-85f6-ff117f8a43cc' },\n",
      "    { id: '97353508-c3d5-4c16-9b13-ab792aabd89b' },\n",
      "    { id: 'a59d30c4-4ff6-4ade-b7b7-72130510fdc2' },\n",
      "    { id: 'c63472f4-bd4d-4469-96a5-8eb01cd5fad2' },\n",
      "    { id: '0f221405-317e-4c2a-ac61-7ad049a3bcf4' },\n",
      "    { id: 'de3767fe-d129-4218-b062-4b3c689797a6' },\n",
      "    { id: 'ba25d45b-6d25-467e-bf25-0106088d9da8' },\n",
      "    { id: '755a56bf-ba20-4fc6-885b-97b1f1389cca' },\n",
      "    { id: '4a391f87-1ccb-4f66-8cc8-d7a7f98c1455' },\n",
      "    { id: '844ef3dc-9281-4912-9ddb-52260891237d' },\n",
      "    { id: 'c9b88bc9-6711-4c1d-a44d-878f3c9567d3' },\n",
      "    { id: 'cff9d8f9-0037-4666-a9a6-bbdce8ec6281' },\n",
      "    { id: '5c1ca925-732a-4eb1-b89e-222149802725' },\n",
      "    { id: '8189a997-b7db-412c-a24a-d2ad899996c3' },\n",
      "    { id: '3b84ebcb-83ff-4c28-a820-ba220b1182e0' },\n",
      "    { id: 'cee3e54f-28da-44ba-8e89-3e7190da9c4d' },\n",
      "    { id: '7b8c2bfd-4e60-4dc0-9925-d91f12687bb9' },\n",
      "    { id: '6ee122b7-711c-41b3-8cff-c91c937521fb' },\n",
      "    { id: '90cfc70d-ed91-40df-a950-6156b58a958d' },\n",
      "    { id: 'f65b5f7c-6188-4fbc-97a3-fe4a9a0195ef' },\n",
      "    { id: '93838d7f-cbc1-49c0-b1c3-7346890a33c6' },\n",
      "    { id: '4a151e15-2168-4c82-9328-ec9b38d74a33' },\n",
      "    { id: '468454c2-3de2-4fb9-94d4-0401bd6bbe5a' },\n",
      "    { id: '01bdc318-486d-4fc3-9494-54e89528b837' },\n",
      "    { id: '9ec60200-82d7-4be9-ac08-0b23ec063bbd' },\n",
      "    { id: 'c14d0c79-9fcf-4881-97b9-28a26909623b' },\n",
      "    { id: '5dd44111-2198-4450-a775-a127f1871113' },\n",
      "    { id: '893ebdd6-03c4-4bb0-804c-6450c878a9ea' },\n",
      "    { id: '31a4d42a-7754-4577-8ba3-0a3f8211de83' },\n",
      "    { id: '77d5342d-4ba5-456b-8847-f4035db744fc' },\n",
      "    { id: '99b1d564-b7c2-4ca1-9ffc-32a166750e79' },\n",
      "    { id: 'b42d8825-beb6-408d-a52a-ee173c0145e1' },\n",
      "    { id: '18e26f1c-e144-4777-8f5f-776de83fb3be' },\n",
      "    { id: 'f8c0c005-4d91-46f7-b814-9b4b13899e30' },\n",
      "    { id: '6ba1713f-edc4-42bd-860b-96919be6571d' },\n",
      "    { id: 'aa5bc2b5-4f0a-4c22-9612-998c5cd69bb1' },\n",
      "    { id: '91b91359-d140-458e-8fab-83ee5453a790' },\n",
      "    { id: 'bbf9a474-4f3a-4abf-9342-699d2e9fe409' },\n",
      "    { id: '9f0bf3da-5c8e-45aa-bc48-3d4e61c3ebdb' },\n",
      "    { id: '1be204e4-70b0-47fc-b21e-7224eab69a75' },\n",
      "    { id: 'be8393f0-ca5f-45c9-b1d7-986a303d0369' },\n",
      "    { id: '89be8879-eb8b-46a6-82e2-e51792f681b9' },\n",
      "    { id: '6068a764-8f01-4cbd-97f5-53350c8a05a0' },\n",
      "    { id: '2522017c-9477-472d-8108-d76459ba8aa7' },\n",
      "    { id: 'a691255f-4a4c-48ec-a3a3-80aba6c18c79' },\n",
      "    { id: 'd2fb69aa-4717-445f-92cb-508218940968' },\n",
      "    { id: 'db3123f4-4123-46b9-b9f4-0e6e1fa7e3c3' },\n",
      "    { id: '40f718e8-6881-4bb9-9d39-13aab528056d' },\n",
      "    { id: 'a5dbff0a-3b09-4d12-b8ad-654bce0f5dee' },\n",
      "    { id: '6aea630d-a505-49cf-8d10-8174bd4faa15' },\n",
      "    { id: '496d2ee5-ab26-46b4-8b9d-7acc9ea36075' },\n",
      "    { id: 'd34e623c-072f-49d3-9e94-4b70fcda51b2' },\n",
      "    { id: '938c7da4-2359-488e-89b8-fb4be3ce5b01' },\n",
      "    { id: 'e6ebe707-26b2-4b18-91cc-a4a331217b2a' },\n",
      "    { id: 'b025fdeb-35b7-46cc-85d1-3ec4ca0caddc' },\n",
      "    { id: 'ddead230-69b3-410d-9eea-e89545dfff25' },\n",
      "    { id: 'e00c5fe1-c425-4bea-9c37-0836c2c6befa' },\n",
      "    { id: 'fb934adb-735c-4fed-a052-d896ddd437bf' },\n",
      "    { id: 'ae420132-f438-4ff4-b992-3a3ccb69a5ef' },\n",
      "    { id: '38784dc9-ecdd-4759-97a8-4ee22aca4634' },\n",
      "    { id: '9d56a989-f2d2-4ad5-9e49-1898dd6e75f2' },\n",
      "    { id: 'fd844e2f-d433-46c2-87d6-b3c64535a8a2' },\n",
      "    { id: '18400d6c-ab86-4f50-86aa-4b234b62f009' },\n",
      "    { id: 'a4494df8-bfd6-44c6-b8b2-b81ff61a74fe' },\n",
      "    { id: 'f8f51316-2feb-4b31-9e46-4689bf46787c' },\n",
      "    { id: 'df12bf50-6dd4-492b-9c18-0e2e4841a4a4' },\n",
      "    { id: '34ceec9a-0016-43c0-8c55-7fcfe4495a8b' },\n",
      "    { id: '4f6ea7fc-2786-45f1-a4d2-7ecfbd36582a' },\n",
      "    { id: '71767cfe-8200-4971-820b-73129cdc9545' },\n",
      "    { id: '202e0e63-e8a5-4f7d-8484-4d46aad50d7f' },\n",
      "    { id: 'bd131dd5-5d7b-45b1-9799-1ffb62d98797' },\n",
      "    { id: 'a565e1b0-c95b-4e11-a3d6-c63866c31261' },\n",
      "    { id: '1feb01f4-846c-494d-a6b8-5f4537fca483' },\n",
      "    { id: 'a2c43dbe-dd5a-49eb-9cf6-38746b7d1f5c' },\n",
      "    { id: 'd8c2ffce-9430-4a0b-8693-1aacca4182dd' },\n",
      "    { id: '315485dc-3489-4d76-872e-265b70a48bed' },\n",
      "    { id: '4ff4df53-51dd-4735-b7ec-1ad08951e16e' },\n",
      "    { id: 'c6f489c6-e661-4dd0-a648-94876c401f76' },\n",
      "    { id: 'b807e746-b164-4d77-9920-add981023992' },\n",
      "    { id: 'f326c9c3-fec6-4261-aad3-ca1e6c24e3e0' },\n",
      "    { id: '4c03255a-7007-4b62-89f9-7102969d292b' },\n",
      "    { id: '771daa63-07ad-4342-b1e8-8ea7236b5e03' },\n",
      "    { id: '0dc20776-a46a-49cf-a85e-9d76fd294360' },\n",
      "    { id: 'd6270cad-f2c1-4832-84dd-af0d4b757226' },\n",
      "    { id: '1d105310-5247-4bf1-8594-c8f32b2d1b7e' },\n",
      "    ... 193 more items\n",
      "  ],\n",
      "  count: 293,\n",
      "  status: 200,\n",
      "  statusText: 'OK'\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "//count the number of documents in the vector store\n",
    "\n",
    "await vectorStore.client.from('documents').select('id', { count: \n",
    "'exact'});\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[\n",
      "  Document {\n",
      "    pageContent: 'security\\tincidents,\\twhich\\tcould\\tresult\\tin\\tdata\\tbreaches,\\tintellectual\\tproperty\\ttheft,\\tclaims,\\tlitigation,\\tregulatory\\tinvestigations,\\tsignificant\\tliability,\\n' +\n",
      "      'reputational\\tdamage\\tand\\tother\\tadverse\\tconsequences”\\tincluded\\tas\\tpart\\tof\\tour\\trisk\\tfactor\\tdisclosures\\tat\\tItem\\t1A\\tof\\tthis\\tAnnual\\tReport\\ton\\tForm\\t10-K.\\n' +\n",
      "      'Cybersecurity\\tGovernance\\n' +\n",
      "      'Cybersecurity\\tis\\tan\\timportant\\tpart\\tof\\tour\\trisk\\tmanagement\\tprocesses\\tand\\tan\\tarea\\tof\\tfocus\\tfor\\tour\\tBoard\\tand\\tmanagement.\\tOur\\tAudit\\tCommittee\\tis\\n' +\n",
      "      'responsible\\tfor\\tthe\\toversight\\tof\\trisks\\tfrom\\tcybersecurity\\tthreats.\\tMembers\\tof\\tthe\\tAudit\\tCommittee\\treceive\\tupdates\\ton\\ta\\tquarterly\\tbasis\\tfrom\\tsenior\\n' +\n",
      "      'management,\\tincluding\\tleaders\\tfrom\\tour\\tInformation\\tSecurity,\\tProduct\\tSecurity,\\tCompliance\\tand\\tLegal\\tteams\\tregarding\\tmatters\\tof\\tcybersecurity.\\tThis\\n' +\n",
      "      'includes\\texisting\\tand\\tnew\\tcybersecurity\\trisks,\\tstatus\\ton\\thow\\tmanagement\\tis\\taddressing\\tand/or\\tmitigating\\tthose\\trisks,\\tcybersecurity\\tand\\tdata\\tprivacy\\n' +\n",
      "      'incidents\\t(if\\tany)\\tand\\tstatus\\ton\\tkey\\tinformation\\tsecurity\\tinitiatives.\\tOur\\tBoard\\tmembers\\talso\\tengage\\tin\\tad\\thoc\\tconversations\\twith\\tmanagement\\ton\\n' +\n",
      "      'cybersecurity-related\\tnews\\tevents\\tand\\tdiscuss\\tany\\tupdates\\tto\\tour\\tcybersecurity\\trisk\\tmanagement\\tand\\tstrategy\\tprograms.\\n' +\n",
      "      '29',\n",
      "    metadata: {\n",
      "      loc: [Object],\n",
      "      pdf: [Object],\n",
      "      uuid: '6068a764-8f01-4cbd-97f5-53350c8a05a0',\n",
      "      source: './test_docs/test-tsla-10k-2023.pdf'\n",
      "    },\n",
      "    id: undefined\n",
      "  },\n",
      "  Document {\n",
      "    pageContent: 'Risks\\tRelated\\tto\\tOur\\tAbility\\tto\\tGrow\\tOur\\tBusiness\\n' +\n",
      "      'We\\tmay\\texperience\\tdelays\\tin\\tlaunching\\tand\\tramping\\tthe\\tproduction\\tof\\tour\\tproducts\\tand\\tfeatures,\\tor\\twe\\tmay\\tbe\\tunable\\tto\\tcontrol\\n' +\n",
      "      'our\\tmanufacturing\\tcosts.\\n' +\n",
      "      'We\\thave\\tpreviously\\texperienced\\tand\\tmay\\tin\\tthe\\tfuture\\texperience\\tlaunch\\tand\\tproduction\\tramp\\tdelays\\tfor\\tnew\\tproducts\\tand\\tfeatures.\\tFor\\texample,\\n' +\n",
      "      'we\\tencountered\\tunanticipated\\tsupplier\\tissues\\tthat\\tled\\tto\\tdelays\\tduring\\tthe\\tinitial\\tramp\\tof\\tour\\tfirst\\tModel\\tX\\tand\\texperienced\\tchallenges\\twith\\ta\\tsupplier\\tand\\n' +\n",
      "      'with\\tramping\\tfull\\tautomation\\tfor\\tcertain\\tof\\tour\\tinitial\\tModel\\t3\\tmanufacturing\\tprocesses.\\tIn\\taddition,\\twe\\tmay\\tintroduce\\tin\\tthe\\tfuture\\tnew\\tor\\tunique\\n' +\n",
      "      'manufacturing\\tprocesses\\tand\\tdesign\\tfeatures\\tfor\\tour\\tproducts.\\tAs\\twe\\texpand\\tour\\tvehicle\\tofferings\\tand\\tglobal\\tfootprint,\\tthere\\tis\\tno\\tguarantee\\tthat\\twe\\twill\\n' +\n",
      "      'be\\table\\tto\\tsuccessfully\\tand\\ttimely\\tintroduce\\tand\\tscale\\tsuch\\tprocesses\\tor\\tfeatures.\\n' +\n",
      "      '14',\n",
      "    metadata: {\n",
      "      loc: [Object],\n",
      "      pdf: [Object],\n",
      "      uuid: '4a151e15-2168-4c82-9328-ec9b38d74a33',\n",
      "      source: './test_docs/test-tsla-10k-2023.pdf'\n",
      "    },\n",
      "    id: undefined\n",
      "  },\n",
      "  Document {\n",
      "    pageContent: 'Employees\\tare\\tencouraged\\tto\\tspeak\\tup\\tboth\\tin\\tregard\\tto\\tmisconduct\\tand\\tsafety\\tconcerns\\tand\\tcan\\tdo\\tso\\tby\\tcontacting\\tthe\\tintegrity\\tline,\\tsubmitting\\n' +\n",
      "      'concerns\\tthrough\\tour\\tTake\\tCharge\\tprocess,\\tor\\tnotifying\\ttheir\\tHuman\\tResource\\tPartner\\tor\\tany\\tmember\\tof\\tmanagement.\\tConcerns\\tare\\treviewed\\tin\\n' +\n",
      "      'accordance\\twith\\testablished\\tprotocols\\tby\\tinvestigators\\twith\\texpertise,\\twho\\talso\\treview\\tfor\\ttrends\\tand\\toutcomes\\tfor\\tremediation\\tand\\tappropriate\\tcontrols.\\n' +\n",
      "      'Responding\\tto\\tquestions\\ttimely\\tis\\tkey\\tso\\tHuman\\tResource\\tPartners\\tfor\\teach\\tfunctional\\tarea\\tare\\tvisible\\tthroughout\\tfacilities\\tand\\tare\\tactively\\tinvolved\\tin\\n' +\n",
      "      'driving\\tculture\\tand\\tengagement\\talongside\\tbusiness\\tleaders.\\n' +\n",
      "      'Available\\tInformation\\n' +\n",
      "      'We\\tfile\\tor\\tfurnish\\tperiodic\\treports\\tand\\tamendments\\tthereto,\\tincluding\\tour\\tAnnual\\tReports\\ton\\tForm\\t10-K,\\tour\\tQuarterly\\tReports\\ton\\tForm\\t10-Q\\tand\\n' +\n",
      "      'Current\\tReports\\ton\\tForm\\t8-K,\\tproxy\\tstatements\\tand\\tother\\tinformation\\twith\\tthe\\tSEC.\\tIn\\taddition,\\tthe\\tSEC\\tmaintains\\ta\\twebsite\\t(www.sec.gov)\\tthat\\tcontains\\n' +\n",
      "      'reports,\\tproxy\\tand\\tinformation\\tstatements,\\tand\\tother\\tinformation\\tregarding\\tissuers\\tthat\\tfile\\telectronically.\\tOur\\twebsite\\tis\\tlocated\\tat\\twww.tesla.com,\\tand\\n' +\n",
      "      'our\\treports,\\tamendments\\tthereto,\\tproxy\\tstatements\\tand\\tother\\tinformation\\tare\\talso\\tmade\\tavailable,\\tfree\\tof\\tcharge,\\ton\\tour\\tinvestor\\trelations\\twebsite\\tat\\n' +\n",
      "      'ir.tesla.com\\tas\\tsoon\\tas\\treasonably\\tpracticable\\tafter\\twe\\telectronically\\tfile\\tor\\tfurnish\\tsuch\\tinformation\\twith\\tthe\\tSEC.\\tThe\\tinformation\\tposted\\ton\\tour\\twebsite\\n' +\n",
      "      'is\\tnot\\tincorporated\\tby\\treference\\tinto\\tthis\\tAnnual\\tReport\\ton\\tForm\\t10-K.\\n' +\n",
      "      'ITEM\\t1A.\\tRISK\\tFACTORS\\n' +\n",
      "      'You\\tshould\\tcarefully\\tconsider\\tthe\\trisks\\tdescribed\\tbelow\\ttogether\\twith\\tthe\\tother\\tinformation\\tset\\tforth\\tin\\tthis\\treport,\\twhich\\tcould\\tmaterially\\taffect\\tour\\n' +\n",
      "      'business,\\tfinancial\\tcondition\\tand\\tfuture\\tresults.\\tThe\\trisks\\tdescribed\\tbelow\\tare\\tnot\\tthe\\tonly\\trisks\\tfacing\\tour\\tcompany.\\tRisks\\tand\\tuncertainties\\tnot\\tcurrently\\n' +\n",
      "      'known\\tto\\tus\\tor\\tthat\\twe\\tcurrently\\tdeem\\tto\\tbe\\timmaterial\\talso\\tmay\\tmaterially\\tadversely\\taffect\\tour\\tbusiness,\\tfinancial\\tcondition\\tand\\toperating\\tresults.',\n",
      "    metadata: {\n",
      "      loc: [Object],\n",
      "      pdf: [Object],\n",
      "      uuid: '93838d7f-cbc1-49c0-b1c3-7346890a33c6',\n",
      "      source: './test_docs/test-tsla-10k-2023.pdf'\n",
      "    },\n",
      "    id: undefined\n",
      "  },\n",
      "  Document {\n",
      "    pageContent: 'damage,\\tinterruptions,\\tsystem\\tmalfunctions,\\tpower\\toutages,\\tterrorism,\\tacts\\tof\\tvandalism,\\tsecurity\\tbreaches,\\tsecurity\\tincidents,\\tinadvertent\\tor\\tintentional\\n' +\n",
      "      'actions\\tby\\temployees\\tor\\tother\\tthird\\tparties,\\tand\\tother\\tcyber-attacks.\\n' +\n",
      "      'To\\tthe\\textent\\tany\\tsecurity\\tincident\\tresults\\tin\\tunauthorized\\taccess\\tor\\tdamage\\tto\\tor\\tacquisition,\\tuse,\\tcorruption,\\tloss,\\tdestruction,\\talteration\\tor\\n' +\n",
      "      'dissemination\\tof\\tour\\tdata,\\tincluding\\tintellectual\\tproperty\\tand\\tpersonal\\tinformation,\\tor\\tour\\tproducts\\tor\\tvehicles,\\tor\\tfor\\tit\\tto\\tbe\\tbelieved\\tor\\treported\\tthat\\tany\\n' +\n",
      "      'of\\tthese\\toccurred,\\tit\\tcould\\tdisrupt\\tour\\tbusiness,\\tharm\\tour\\treputation,\\tcompel\\tus\\tto\\tcomply\\twith\\tapplicable\\tdata\\tbreach\\tnotification\\tlaws,\\tsubject\\tus\\tto\\ttime\\n' +\n",
      "      'consuming,\\tdistracting\\tand\\texpensive\\tlitigation,\\tregulatory\\tinvestigation\\tand\\toversight,\\tmandatory\\tcorrective\\taction,\\trequire\\tus\\tto\\tverify\\tthe\\tcorrectness\\n' +\n",
      "      'of\\tdatabase\\tcontents,\\tor\\totherwise\\tsubject\\tus\\tto\\tliability\\tunder\\tlaws,\\tregulations\\tand\\tcontractual\\tobligations,\\tincluding\\tthose\\tthat\\tprotect\\tthe\\tprivacy\\tand\\n' +\n",
      "      'security\\tof\\tpersonal\\tinformation.\\tThis\\tcould\\tresult\\tin\\tincreased\\tcosts\\tto\\tus\\tand\\tresult\\tin\\tsignificant\\tlegal\\tand\\tfinancial\\texposure\\tand/or\\treputational\\tharm.\\n' +\n",
      "      'We\\talso\\trely\\ton\\tservice\\tproviders,\\tand\\tsimilar\\tincidents\\trelating\\tto\\ttheir\\tinformation\\ttechnology\\tsystems\\tcould\\talso\\thave\\ta\\tmaterial\\tadverse\\teffect\\ton\\n' +\n",
      "      'our\\tbusiness.\\tThere\\thave\\tbeen\\tand\\tmay\\tcontinue\\tto\\tbe\\tsignificant\\tsupply\\tchain\\tattacks.\\tOur\\tservice\\tproviders,\\tincluding\\tour\\tworkforce\\tmanagement\\n' +\n",
      "      'software\\tprovider,\\thave\\tbeen\\tsubject\\tto\\transomware\\tand\\tother\\tsecurity\\tincidents,\\tand\\twe\\tcannot\\tguarantee\\tthat\\tour\\tor\\tour\\tservice\\tproviders’\\tsystems\\n' +\n",
      "      'have\\tnot\\tbeen\\tbreached\\tor\\tthat\\tthey\\tdo\\tnot\\tcontain\\texploitable\\tdefects,\\tbugs,\\tor\\tvulnerabilities\\tthat\\tcould\\tresult\\tin\\ta\\tsecurity\\tincident,\\tor\\tother\\tdisruption\\n' +\n",
      "      'to,\\tour\\tor\\tour\\tservice\\tproviders’\\tsystems.\\tOur\\tability\\tto\\tmonitor\\tour\\tservice\\tproviders’\\tsecurity\\tmeasures\\tis\\tlimited,\\tand,\\tin\\tany\\tevent,\\tmalicious\\tthird\\n' +\n",
      "      'parties\\tmay\\tbe\\table\\tto\\tcircumvent\\tthose\\tsecurity\\tmeasures.',\n",
      "    metadata: {\n",
      "      loc: [Object],\n",
      "      pdf: [Object],\n",
      "      uuid: '40f718e8-6881-4bb9-9d39-13aab528056d',\n",
      "      source: './test_docs/test-tsla-10k-2023.pdf'\n",
      "    },\n",
      "    id: undefined\n",
      "  }\n",
      "]\n"
     ]
    }
   ],
   "source": [
    "await vectorStore.similaritySearch(\"risk factors\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AIMessage {\n",
      "  \"id\": \"chatcmpl-AvntuDz8xFKGEO0DZMK5vBU0xcFZL\",\n",
      "  \"content\": \"The name of the company in the report is Tesla, Inc.\",\n",
      "  \"additional_kwargs\": {},\n",
      "  \"response_metadata\": {\n",
      "    \"tokenUsage\": {\n",
      "      \"promptTokens\": 1653,\n",
      "      \"completionTokens\": 14,\n",
      "      \"totalTokens\": 1667\n",
      "    },\n",
      "    \"finish_reason\": \"stop\",\n",
      "    \"model_name\": \"gpt-4o-2024-08-06\",\n",
      "    \"usage\": {\n",
      "      \"prompt_tokens\": 1653,\n",
      "      \"completion_tokens\": 14,\n",
      "      \"total_tokens\": 1667,\n",
      "      \"prompt_tokens_details\": {\n",
      "        \"cached_tokens\": 0,\n",
      "        \"audio_tokens\": 0\n",
      "      },\n",
      "      \"completion_tokens_details\": {\n",
      "        \"reasoning_tokens\": 0,\n",
      "        \"audio_tokens\": 0,\n",
      "        \"accepted_prediction_tokens\": 0,\n",
      "        \"rejected_prediction_tokens\": 0\n",
      "      }\n",
      "    },\n",
      "    \"system_fingerprint\": \"fp_50cad350e4\"\n",
      "  },\n",
      "  \"tool_calls\": [],\n",
      "  \"invalid_tool_calls\": [],\n",
      "  \"usage_metadata\": {\n",
      "    \"output_tokens\": 14,\n",
      "    \"input_tokens\": 1653,\n",
      "    \"total_tokens\": 1667,\n",
      "    \"input_token_details\": {\n",
      "      \"audio\": 0,\n",
      "      \"cache_read\": 0\n",
      "    },\n",
      "    \"output_token_details\": {\n",
      "      \"audio\": 0,\n",
      "      \"reasoning\": 0\n",
      "    }\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "import { pull } from \"langchain/hub\";\n",
    "import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n",
    "import { z } from \"zod\";\n",
    "import { ChatOpenAI } from \"@langchain/openai\";\n",
    "\n",
    "const retriever = vectorStore.asRetriever({\n",
    "  k: 2,\n",
    "})\n",
    "\n",
    "const answerSchema = z.object({\n",
    "  answer: z.string().describe(\"The answer to the question\"),\n",
    "  sources: z.array(z.string()).describe(\"The full text of the documents used to answer the question\"),\n",
    "});\n",
    "\n",
    "const llm = new ChatOpenAI({\n",
    "    model: \"gpt-4o\",\n",
    "    temperature: 0,\n",
    "  })\n",
    "\n",
    "\n",
    "const promptTemplate = await pull<ChatPromptTemplate>(\"rlm/rag-prompt\");\n",
    "\n",
    "const query = \"What is the name of the company in the report?\"\n",
    "\n",
    "const retrievedDocs = await retriever.invoke(query)\n",
    "\n",
    "const formattedPrompt = await promptTemplate.invoke({\n",
    "  context: retrievedDocs,\n",
    "  question: query,\n",
    "});\n",
    "\n",
    "const response = await llm.invoke(formattedPrompt);\n",
    "\n",
    "console.log(response);\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  error: {\n",
      "    code: '22P02',\n",
      "    details: null,\n",
      "    hint: null,\n",
      "    message: 'invalid input syntax for type uuid: \"\"'\n",
      "  },\n",
      "  data: null,\n",
      "  count: null,\n",
      "  status: 400,\n",
      "  statusText: 'Bad Request'\n",
      "}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "UncaughtException: Error: Unexpected pending rebuildTimer\n",
      "    at sys.setTimeout (/opt/homebrew/lib/node_modules/tslab/dist/converter.js:111:19)\n",
      "    at Object.scheduleInvalidateResolutionsOfFailedLookupLocations (/opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:122719:55)\n",
      "    at scheduleInvalidateResolutionOfFailedLookupLocation (/opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:121553:22)\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:121474:9\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:5810:11\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:5560:101\n",
      "    at Array.forEach (<anonymous>)\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:5560:85\n",
      "    at FSWatcher.callbackChangingToMissingFileSystemEntry (/opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:6104:11)\n",
      "    at FSWatcher.emit (node:events:518:28)\n",
      "UncaughtException: Error: Unexpected pending rebuildTimer\n",
      "    at sys.setTimeout (/opt/homebrew/lib/node_modules/tslab/dist/converter.js:111:19)\n",
      "    at Object.scheduleInvalidateResolutionsOfFailedLookupLocations (/opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:122719:55)\n",
      "    at scheduleInvalidateResolutionOfFailedLookupLocation (/opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:121553:22)\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:121474:9\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:5810:11\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:5560:101\n",
      "    at Array.forEach (<anonymous>)\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:5560:85\n",
      "    at FSWatcher.callbackChangingToMissingFileSystemEntry (/opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:6104:11)\n",
      "    at FSWatcher.emit (node:events:518:28)\n",
      "UncaughtException: Error: Unexpected pending rebuildTimer\n",
      "    at sys.setTimeout (/opt/homebrew/lib/node_modules/tslab/dist/converter.js:111:19)\n",
      "    at Object.scheduleInvalidateResolutionsOfFailedLookupLocations (/opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:122719:55)\n",
      "    at scheduleInvalidateResolutionOfFailedLookupLocation (/opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:121553:22)\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:121474:9\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:5810:11\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:5560:101\n",
      "    at Array.forEach (<anonymous>)\n",
      "    at /opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:5560:85\n",
      "    at FSWatcher.callbackChangingToMissingFileSystemEntry (/opt/homebrew/lib/node_modules/tslab/node_modules/@tslab/typescript-for-tslab/lib/typescript.js:6104:11)\n",
      "    at FSWatcher.emit (node:events:518:28)\n"
     ]
    }
   ],
   "source": [
    "// delete all documents from the vector store\n",
    "\n",
    "await vectorStore.client.from('documents').delete().neq('id', '');\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "TypeScript",
   "language": "typescript",
   "name": "tslab"
  },
  "language_info": {
   "codemirror_mode": {
    "mode": "typescript",
    "name": "javascript",
    "typescript": true
   },
   "file_extension": ".ts",
   "mimetype": "text/typescript",
   "name": "typescript",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
